package main

import (
	"fmt"
)

// 通道工厂模式

func main() {
	ch := genCh(11)
	res := printInt(ch, 11)
	<-res
	// time.Sleep(5e9)
	fmt.Println("main done")
}

func genCh(n int) chan int {
	ch := make(chan int)
	go func() {
		for i := 0; i < n; i++ {
			ch <- i * 10
		}
		close(ch)
	}()

	return ch
}

func printInt(ch <-chan int, n int) chan bool {
	res := make(chan bool)
	go func() {
		for i := 0; i < n; i++ {
			fmt.Println(<-ch)
		}
		res <- true
	}()

	return res
}
